package R.Service;

import R.Dao.RegDao;
import R.Entity.Record;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "EditServlet", value = "/RegEditServlet")
public class RegEditServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //获取传递参数
        String RegistrationID=request.getParameter("RegistrationID");
        Record r=new Record();
        r.setRegistrationID(RegistrationID);
        Record r1= RegDao.getR(r);
        HttpSession session=request.getSession();
        session.setAttribute("editR",r1);
        response.sendRedirect("/R/regEdit.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //获取值
        String RegistrationID = request.getParameter("bh");//挂号单编号
        String RegType = request.getParameter("RegType");//获取门诊类型
        String CardID = request.getParameter("CardID");//获取就诊卡号
        String Name = request.getParameter("Name");//获取病人姓名
        String Gender = request.getParameter("Gender");//获取病人性别
        String age = request.getParameter("Age");//获取病人年龄
        int Age = Integer.parseInt(age);
        String DepName = request.getParameter("DepName");//获取挂号科室
        String Department = request.getParameter("Department");//获取挂号类型
        String DoctorName = request.getParameter("DoctorName");//获取就诊医生
        String RegDate = request.getParameter("RegDate");//获取挂号时间
        String Operator = request.getParameter("Operator");//获取操作人员
        //创建实体类
        Record r = new Record();
        r.setCardID(CardID);
        r.setRegistrationID(RegistrationID);
        r.setName(Name);
        r.setGender(Gender);
        r.setAge(Age);
        r.setDoctorName(DoctorName);
        r.setDepartment(Department);
        r.setRegType(RegType);
        r.setVenue("佛山市第二人民医院");
        if (RegType.equals("普通门诊")) {
            r.setFee(50);
        } else {
            r.setFee(100);
        }
        r.setRegDate(RegDate);
        r.setOperator(Operator);
        r.setDepName(DepName);
        int sta=RegDao.udateR(r);
        if (sta>0){
            response.sendRedirect("/RegShowAll");
        }else {
            response.sendRedirect("/RegEditServlet");
        }
    }
}
